< previous page page_808 next page >

Page 808
The LIKE predicate is used exclusively for string comparisons. The format of the LIKE predicate is as follows:
expression LIKE pattern
The patterns defined for the LIKE predicate make use of wild-card matching and character-range lists. When you create a pattern, you can combine some of the wild cards and character lists to allow greater flexibility in the pattern definition. When used, character lists must meet three criteria:
The list must be enclosed within square brackets.
The first and last characters must be separated by a hyphen.
The range of the characters must be defined in ascending order (for example, a z, and not z a).
In addition to using a character list to match a character in the list, you can precede the list with an exclamation point to indicate that you want to exclude the characters in the list. Table C.4 shows the type of pattern matching you can perform with the LIKE predicate. Listing C.10 shows the use of the LIKE predicate in several SELECT statements.
Table C.4 The LIKE Predicate Using a Variety of Pattern Matching
Wild CardUsed to MatchExample PatternExample Results
*Multiple charactersS*Smith, Sims, sheep
?Single characteran?and, ant, any
#Single digit3524#35242, 35243
[list]Single character in list[c-f]d, e, f
[!list]Single character not in list[!c-f]a, b, g, h
combinationSpecific to patterna?t*art, antique, artist

Listing C.10 LIKE.TXTUse the LIKE Predicate for Pattern-Matching
'***************************
'Multiple character wild card
'***************************
SELECT * FROM Customers WHERE Lastname LIKE 'S*'
'*************************
'Single character wild card
'*************************
SELECT * FROM Customers WHERE State LIKE '?L'
'***********************

 
< previous page page_808 next page >